package com.ruoyi.web.controller.pc;


import com.ruoyi.business.domain.WmsInWarehousDetail;
import com.ruoyi.business.domain.WmsTransfer;
import com.ruoyi.business.service.IWmsInWarehousDetailService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 入库单详情管理 Controller
 *
 * @author patton
 * @date 2023-07-16
 */
@RestController
@RequestMapping("/business/inWarehousDetail")
public class WmsInWarehousDetailController extends BaseController {

    @Autowired
    private IWmsInWarehousDetailService wmsInWarehousDetailService;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 新增
     */
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WmsInWarehousDetail info)
    {
        wmsInWarehousDetailService.insertWmsInWarehousDetail(info);
        return AjaxResult.success();
    }

    /**
     * 删除
     */
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody WmsInWarehousDetail info)
    {
        wmsInWarehousDetailService.deleteWmsInWarehousDetailById(info.getId());
        return AjaxResult.success();
    }

    /**
     * 更新
     */
    @Log(title = "更新", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody WmsInWarehousDetail info)
    {
        wmsInWarehousDetailService.updateWmsInWarehousDetail(info);
        return AjaxResult.success();
    }

    /**
     * @Description: 列表
     * @author yunlong
     */
    @ApiOperation(value = "列表")
    @GetMapping("list")
    @CrossOrigin
    public TableDataInfo queryList(WmsInWarehousDetail info) {
        info.setType(1);
        startPage();
        List<WmsInWarehousDetail> list = wmsInWarehousDetailService.selectWmsInWarehousDetailList(info);
        return getDataTable(list);
    }

    /**
     * @Description: 列表
     * @author yunlong
     */
    @ApiOperation(value = "列表")
    @GetMapping("queryAllList")
    @CrossOrigin
    public AjaxResult queryAllList(WmsInWarehousDetail info) {
        info.setType(1);
        List<WmsInWarehousDetail> list = wmsInWarehousDetailService.selectWmsInWarehousDetailList(info);
        return AjaxResult.success(list);
    }

    /**
     * @Description: 审核列表
     * @author yunlong
     */
    @ApiOperation(value = "审核列表")
    @GetMapping("queryProcessList")
    @CrossOrigin
    public TableDataInfo queryProcessList(WmsInWarehousDetail info) {
        info.setType(2);
        startPage();
        List<WmsInWarehousDetail> list = wmsInWarehousDetailService.selectWmsInWarehousDetailList(info);
        return getDataTable(list);
    }

    /**
     * 审核
     */
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @PostMapping("/process")
    public AjaxResult process(@RequestBody WmsInWarehousDetail info)
    {
        SysUser sysUser = sysUserService.selectUserById(getUserId());
        info.setProcessTime(new Date());
        info.setProcessUser(sysUser.getNickName());
        wmsInWarehousDetailService.processData(info);
        return AjaxResult.success();
    }

    /**
     * @Description: 查询入库单里面可以调拨的商品列表
     * @author yunlong
     */
    @ApiOperation(value = "查询入库单里面可以调拨的商品列表")
    @GetMapping("queryTransferList")
    @CrossOrigin
    public AjaxResult queryTransferList(WmsTransfer info) {
        List<WmsInWarehousDetail> list = wmsInWarehousDetailService.queryGoodList(info);
        return AjaxResult.success(list);
    }

    /**
     * @Description: 过期预警列表
     * @author yunlong
     */
    @ApiOperation(value = "过期预警列表")
    @GetMapping("queryValidityList")
    @CrossOrigin
    public TableDataInfo queryValidityList(WmsInWarehousDetail info) {
        List<WmsInWarehousDetail> list = wmsInWarehousDetailService.queryValidityList(info);
        return getDataTable(list);
    }

    /**
     * @Description: 查询库存商品列表
     * @author yunlong
     */
    @ApiOperation(value = "查询库存商品列表")
    @GetMapping("queryStoreList")
    @CrossOrigin
    public AjaxResult queryStoreList(WmsInWarehousDetail info) {
        List<WmsInWarehousDetail> list = wmsInWarehousDetailService.queryStoreList(info);
        return AjaxResult.success(list);
    }
}
